<?php
class PreparationREQ
{
    //Variables qui contiendront la  pr�paration des requ�tes
    private $ReqSelectById;
    private $ReqSelectByName;
    private $ReqSelectAll;
    private $ReqInsert;
    private $ReqTruncate;


    public function __construct($db)
    {
    	//variables renseignées lors de la pr�paration des requ�tes
	
        $this->ReqSelectAll = $db->prepare("SELECT idecole, nomecole, ville FROM ecole ORDER BY nomecole");
		
        $this->ReqSelectById = $db->prepare("SELECT id, name FROM user WHERE id = ?");
       
 	    $this->ReqSelectByName = $db->prepare("SELECT id, name FROM user WHERE name LIKE ? ORDER BY name, id");
        
		$this->ReqInsertEcole = $db->prepare("INSERT INTO ecole(NOMECOLE, VILLE, login, password) VALUES (:name, :city, :login, :password)");
		//$this->ReqInsert = $db->prepare("INSERT INTO ecole(nomecole, ville) VALUES (:name, :city)");
		
       $this->ReqTruncate = $db->prepare("TRUNCATE user");
       
       
       
       //REQUETES AFFICHAGE 
       //$this->ReqSelectCorps = $db->prepare("");
       
       $this->ReqSelectMenu = $db->prepare("SELECT menu FROM pagesite WHERE titre LIKE :name ");
    }


//Requêtes préparées
	public function InsertEcole($name, $city, $login, $password)
    {
        $this->ReqInsertEcole->execute(
            array(':name' => $name, ':city' => $city, ':login' => $login, ':password' => $password));

        //return $this->ReqInsert->rowCount();
    }
	public function selectCorps(){
		$this->ReqSelectCorps->execute();
		return $this->ReqSelectCorps->fetchAll();
	}
    public function selectAll()
    {
    	$this->ReqSelectAll->execute();
        return $this->ReqSelectAll->fetchAll();
    }

	public function selectById($id)
    {
        $this->ReqSelectById->execute(array($id));
        return $this->ReqSelectById ->fetch();
    }

    public function selectByName($name)
    {
        $this->ReqSelectByName->execute(array('%'.$name.'%'));
        return $this->ReqSelectByName->fetch();
    }
    
    public function SelectMenu($nompage)
    {
    	$this->ReqSelectMenu->execute(array(':name'=>$nompage));
    	return $this->ReqSelectMenu->fetch(PDO::FETCH_OBJ);
    }
    
	public function truncate()
    {
        return $this->ReqTruncate->execute();
    }
    
    
	
}